﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

public enum BattleActionType
{
        PersonAttack,
        PersonUseTools_To_Player,
        PersonUseTools_To_Enemy,
        PersonFangWei,
        PersonTaoPao,
        BaseEnemyAttack,
        TankZhuPaoAttack

}
[System.Serializable]
public class BattleAction : IComparable
{
    public GameObject owner;

    public Vector3 targetPos;

    public BattleActionType actiontype;
    /// <summary>
    /// 执行该动作-的animation中文名字
    /// </summary>
    public string action_animationName;
    /// <summary>
    /// 玩家角色-普通攻击下，，远程攻击的prefab中文名
    /// </summary>
    public string person_long_range_attack_fireName;
    /// <summary>
    /// 玩家角色-状态下，使用对我方玩家使用的物品的中文名
    /// </summary>
    public string person_usetools_to_player_objectName;
    /// <summary>
    /// 玩家角色-状态下，向对敌人使用的物品的中文名
    /// </summary>
    public string person_usetools_to_enemy_objectName;

    public int attack_point;

    public int  next_trun_speed;

    public BattleAction()
    {

    }

    public BattleAction( GameObject  _owner ,  Vector3 _targetpos , BattleActionType  _type ,  string  _action_animaton ,
        string _person_long_range_attack_fireName  ,   string _person_usetools_to_player_objectName , 
        string _person_usetools_to_enemy_objectName  , int _nextspeed)
    {
        owner = _owner;
        targetPos = _targetpos;
        actiontype = _type;
        action_animationName = _action_animaton;
        person_long_range_attack_fireName = _person_long_range_attack_fireName;
        person_usetools_to_player_objectName = _person_usetools_to_player_objectName;
        person_usetools_to_enemy_objectName = _person_usetools_to_enemy_objectName;
        next_trun_speed = _nextspeed;
    }

    public void DoAction()
    {
        //执行动作之前，，先判断动作执行者Owner是否死亡，，如果死亡 则不执行，，，跳下一个
        Do_Attack();
    }

    void Do_Attack()
    {
        if(actiontype == BattleActionType.PersonAttack)
        {
            //先判断子弹对象是否为空，，

            if (person_long_range_attack_fireName  !=null  && person_long_range_attack_fireName.Trim() !="")
            {
                //再生成子弹(  发射点注意  ),,,,,
                //在指定点生成了  敌人 对象
                GameObject fire = ResourcesLoadHepler.LoadPersonFireObject(person_long_range_attack_fireName);
                 GameObject  personfire = GameObject.Instantiate    (   fire  ,  owner.transform.position , owner.transform.rotation );

                personfire.GetComponent<PersonFire>().Set_Attack_Point(  attack_point );

                personfire.GetComponent<PersonFire>().SetTarget_Pos(  targetPos  );


                // GameObject.Instantiate()
                //播放生成子弹的动画
                //设置子弹对象的 向量攻击坐标
            }

        }

        else  if (actiontype == BattleActionType.TankZhuPaoAttack)
        {
            //先判断子弹对象是否为空，，

            if (person_long_range_attack_fireName != null && person_long_range_attack_fireName.Trim() != "")
            {
                //再生成子弹(  发射点注意  ),,,,,
                //在指定点生成了  敌人 对象
                GameObject fire = ResourcesLoadHepler.LoadPersonFireObject(person_long_range_attack_fireName);
                GameObject personfire = GameObject.Instantiate(fire, owner.transform.position, owner.transform.rotation);
                personfire.GetComponent<PersonFire>().SetTarget_Pos(targetPos);

                // GameObject.Instantiate()
                //播放生成子弹的动画
                //设置子弹对象的 向量攻击坐标
            }

        }

        else  if (actiontype == BattleActionType.BaseEnemyAttack)
        {

            if (owner.GetComponent<EnemyInBattle>().isDead())
            {
                TurnSystem.Instance.NextAction();
                return;
            }
            //先判断子弹对象是否为空，，

            if (person_long_range_attack_fireName != null && person_long_range_attack_fireName.Trim() != "")
            {
                //再生成子弹(  发射点注意  ),,,,,
                //在指定点生成了  敌人 对象
                GameObject fire = ResourcesLoadHepler.LoadPersonFireObject(person_long_range_attack_fireName);
                GameObject enemyfire = GameObject.Instantiate(fire, owner.transform.position, owner.transform.rotation);
                EnemyFire ef = enemyfire.GetComponent<EnemyFire>();

                EnemyInBattle e = owner.GetComponent<EnemyInBattle>();
                ef.SetAttackPoint(e.enemy.Attack);
                ef.SetTarget_Pos(targetPos);

                // GameObject.Instantiate()
                //播放生成子弹的动画
                //设置子弹对象的 向量攻击坐标
            }

        }


    }

   

  
    public int CompareTo(object other_obj)
    {
        return next_trun_speed.CompareTo(  (   (BattleAction)other_obj).next_trun_speed);
    }
}
